home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / touch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  6.6 KB  |  225 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. /* undefine any macros for functions defined in this module */
  23. #undef    touchwin
  24. #undef    touchline
  25. #undef    untouchwin
  26. #undef    wtouchln
  27. #undef    is_linetouched
  28. #undef    is_wintouched
  29.  
  30. /* undefine any macros for functions called by this module if in debug mode */
  31. #ifdef PDCDEBUG
  32. #  undef    move
  33. #  undef    wmove
  34. #endif
  35.  
  36. #ifdef PDCDEBUG
  37. char *rcsid_touch  = "$Id$";
  38. #endif
  39.  
  40. /*man-start*********************************************************************
  41.  
  42.   Name:                                                         touch
  43.  
  44.   Synopsis:
  45.       int touchwin(WINDOW *win);
  46.       int touchline(WINDOW *win, int start,int count);
  47.       int untouchwin(WINDOW *win);
  48.       int wtouchln(WINDOW *win, int y, int n, int changed);
  49.       int is_linetouched(WINDOW *win,int line);
  50.       int is_wintouched(WINDOW *win);
  51.  
  52.   X/Open Description:
  53.      The touchwin() and touchline() functions throw away all optimisation 
  54.      information about which parts of the window have been touched, 
  55.      by pretending that the entire window has been drawn on.  
  56.      This is sometimes necessary when using overlapping
  57.      windows, since a change to one window will affect the other window,
  58.      but the records of which lines have been changed in the other
  59.      window will not reflect the change.
  60.  
  61.      The untouchwin() routine marks all lines in the window as unchanged
  62.      since the last call to wrefresh().
  63.  
  64.      The wtouchln() routine makes n lines in the window, starting at 
  65.      line y, look as if they have (changed=1) or have not (changed=0) 
  66.      been changed since the last call to wrefresh().
  67.  
  68.      The is_linetouched() routine returns TRUE if the specified line 
  69.      in the specified window has been changed since the last call to 
  70.      wrefresh(). If the line has not changed, FALSE is returned.
  71.  
  72.      The is_wintouched() routine returns TRUE if the specified window 
  73.      has been changed since the last call to wrefresh(). If the window 
  74.      has not changed, FALSE is returned.
  75.  
  76.   X/Open Return Value:
  77.      All functions return OK on success and ERR on error except
  78.      is_wintouched() and is_linetouched().
  79.  
  80.   X/Open Errors:
  81.      No errors are defined for this function.
  82.  
  83.   Portability                             X/Open    BSD    SYS V
  84.                                           Dec '88
  85.       touchwin                              Y        Y       Y
  86.       touchline                             Y        -      3.0
  87.       untouchwin                            -        -      4.0
  88.       wtouchln                              Y        Y       Y
  89.       is_linetouched                        -        -      4.0
  90.       is_wintouched                         -        -      4.0
  91.  
  92. **man-end**********************************************************************/
  93.  
  94. /***********************************************************************/
  95. int    touchwin(WINDOW *win)
  96. /***********************************************************************/
  97. {
  98.     register int    i;
  99.  
  100. #ifdef PDCDEBUG
  101.     if (trace_on) PDC_debug("touchwin() - called\n");
  102. #endif
  103.  
  104.     if (win == (WINDOW *)NULL)
  105.         return( ERR );
  106.  
  107.     for (i=0;i<win->_maxy;i++)
  108.     {
  109.         win->_firstch[i] = 0;
  110.         win->_lastch[i] = win->_maxx-1;
  111.     }
  112.     return( OK );
  113. }
  114. /***********************************************************************/
  115. int    touchline(WINDOW *win, int start,int count)
  116. /***********************************************************************/
  117. {
  118.     register int i;
  119.  
  120. #ifdef PDCDEBUG
  121.     if (trace_on) PDC_debug("touchline() - called: start %d count %d\n",start,count);
  122. #endif
  123.  
  124.     if (win == (WINDOW *)NULL)
  125.         return( ERR );
  126.  
  127.     if  (start > win->_maxy || start + count > win->_maxy)
  128.         return( ERR );
  129.     for(i=start;i<start+count;i++)
  130.        {
  131.         win->_firstch[i] = 0;
  132.         win->_lastch[i] = win->_maxx - 1;
  133.        }
  134.     return( OK );
  135. }
  136. /***********************************************************************/
  137. int    untouchwin(WINDOW *win)
  138. /***********************************************************************/
  139. {
  140.     register int i;
  141.  
  142. #ifdef PDCDEBUG
  143.     if (trace_on) PDC_debug("untouchwin() - called:");
  144. #endif
  145.  
  146.     if (win == (WINDOW *)NULL)
  147.         return( ERR );
  148.  
  149.     for (i=0;i<win->_maxy;i++)
  150.     {
  151.         win->_firstch[i] = _NO_CHANGE;
  152.         win->_lastch[i] = _NO_CHANGE;
  153.     }
  154.     return(OK);
  155. }
  156. /***********************************************************************/
  157. int    wtouchln(WINDOW *win, int y, int n, int changed)
  158. /***********************************************************************/
  159. {
  160.     register int i;
  161.  
  162. #ifdef PDCDEBUG
  163.     if (trace_on) PDC_debug("wtouchln() - called: y %d n %d changed %d\n",y,n,changed);
  164. #endif
  165.  
  166.     if (win == (WINDOW *)NULL)
  167.         return( ERR );
  168.  
  169.     if  (y > win->_maxy || y + n > win->_maxy)
  170.         return( ERR );
  171.  
  172.     for (i=y;i<y+n;i++)
  173.     {
  174.         if ( changed ) 
  175.         {
  176.             win->_firstch[i] = 0;
  177.             win->_lastch[i] = win->_maxx - 1;
  178.         }
  179.         else 
  180.         {
  181.             win->_firstch[i] = _NO_CHANGE;
  182.             win->_lastch[i] = _NO_CHANGE;
  183.         }
  184.     }
  185.     return( OK );
  186. }
  187. /***********************************************************************/
  188. int    is_linetouched(WINDOW *win,int line)
  189. /***********************************************************************/
  190. {
  191.     register int i;
  192.  
  193. #ifdef PDCDEBUG
  194.     if (trace_on) PDC_debug("is_linetouched() - called\n");
  195. #endif
  196.  
  197.     if (win == NULL)
  198.         return(ERR);
  199.  
  200.     if (line > win->_maxy || line < 0)
  201.         return(ERR);
  202.     if (win->_firstch[line] != _NO_CHANGE) 
  203.         return(TRUE);
  204.     return(FALSE);
  205. }
  206. /***********************************************************************/
  207. int    is_wintouched(WINDOW *win)
  208. /***********************************************************************/
  209. {
  210.     register int i;
  211.  
  212. #ifdef PDCDEBUG
  213.     if (trace_on) PDC_debug("is_wintouched() - called\n");
  214. #endif
  215.  
  216.     if (win == NULL)
  217.         return(ERR);
  218.  
  219.     for (i=0;i<win->_maxy;i++)
  220.         if (win->_firstch[i] != _NO_CHANGE)
  221.             return(TRUE);
  222.     return(FALSE);
  223. }
  224.